const mongoose = require("mongoose");
const bodyParser=require("body-parser");
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");

const dramaRoute = require("./routes/dramaRoute")
const dramaByMulterRoute=require("./routes/dramaByMulterRoute")
const authRoute=require("./routes/authRoute");
const userRoute=require("./routes/userRoute");
const storeRoute=require("./routes/storeRoute");
const playRoute=require("./routes/playRoute");
const reserveRoute=require("./routes/reserveRoute");
const homeDramaRoute=require("./routes/homeDramaRoute");
const bannerRoute=require("./routes/bannerRoute");
const submessageRoute=require("./routes/submessageRoute");



const app = express();

app.use(express.json());
app.use(morgan("tiny"));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}))

app.use('/public',express.static('public'))
app.get('/',(req,res)=>{
    res.status(200).json({message:"helloworld"})
})


app.use('/auth',authRoute)
app.use('/drama',dramaRoute)
app.use("/drama/addByMulter",dramaByMulterRoute)
app.use('/user',userRoute)
app.use('/store',storeRoute)
app.use('/play',playRoute)
app.use('/reserve',reserveRoute)
app.use('/homedrama',homeDramaRoute)
app.use('/banner',bannerRoute)
app.use('/submessage',submessageRoute)


mongoose
    .connect('mongodb://root:Qaz1743822183!@182.61.45.146:27017/JM?authSource=admin')
    .then(() => {
        console.log('正在连接...')
    })
    .then(() => {
        app.listen(5000, () => {
            console.log('服务器运行于 http://182.61.45.146:5000')
        })
    })
    .catch((err) => {
        console.log(`Error:${err}`)
    })